package com.hongxun.modules.bss.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.entity.EPRangeEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.bss.entity.APRangeEntity;
import com.hongxun.modules.bss.service.APRangeService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 项目范围表
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-08-03 13:46:04
 */
@RestController
@RequestMapping("/bss/aprange")
public class APRangeController {
	@Autowired
	private APRangeService aPRangeService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("pGuid")!=null&&!query.get("pGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}
		if(query.get("state")!=null&&query.get("state").toString().equals("isdelno")) {
			wheres += " and  p_r_datastate != '删除' ";
		}
        query.put("filterSql",wheres+" ");
		List<APRangeEntity> aPRangeList = aPRangeService.queryList(query);
		int total = aPRangeService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(aPRangeList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
    public R info(@PathVariable("guid") String guid){
		APRangeEntity aPRange = aPRangeService.queryObject(guid);
		
		return R.ok().put("aPRange", aPRange);
	}
	@RequestMapping("/infoList/{guid}")
	public R infoList(@PathVariable("guid") String guid) {
		Map<String, Object> map = new HashMap<>();
		String wheres = " p_guid = '" + guid+"'";
		map.put("filterSql", wheres + " ");
		List<APRangeEntity> aPRangeList = aPRangeService.queryList(map);
		return R.ok().put("aPRangeList", aPRangeList);
	}
	/**
	 * 保存
	 */
	@RequestMapping("/save")
    public R save(@RequestBody APRangeEntity aPRange){
		aPRange.setPRDatastate("新增");
		aPRangeService.save(aPRange);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody APRangeEntity aPRange){
		aPRange.setPRDatastate("修改");
		aPRangeService.update(aPRange);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		aPRangeService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
